package com.offcn.app.test;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.Test;

import com.swetake.util.Qrcode;

/**
 * <p>
 * Title:
 * </p>
 * <p>
 * Description:
 * </p>
 * <p>
 * Company:
 * </p>
 * 
 * @author Administrator
 * @date 2018年3月20日 下午4:41:42
 */

/*
 * http://localhost:8080/eastCMS/login?userName=admin&password=admin
 */

public class App {
	
	
	
	
	
	
	
	@Test
	public void show002(){
		
		   String path1 = "c:/code";
	        File f = new File(path1);
	        // 创建文件夹
	        if (!f.exists()) {
	            f.mkdirs();
	        }
	       
		
	}
	
	
	
	
	
	

	private SqlSessionFactory sqlSessionFactory;
	private SqlSession session;
	
	
	@Test
	public void show34(){
//		HttpServletRequest request  = null;
//		System.out.println(request.getContextPath());
//		
		
		
		  
        StringBuffer sb = new StringBuffer();
        sb.append("姓名：");
        sb.append("zhaowenzheng ");
        sb.append(",");
//        sb.append("/n/r");
        sb.append("电话：");
        sb.append("11100");
        sb.append(","); 
//        sb.append("/n/r");
        sb.append("住址：");
        sb.append("00000000");
       
       System.out.println("sb===========!!!!!===="+sb.toString().trim().replaceFirst(" ", ""));
		
		
	}
	
	

	@Test
	public void display() {
		Qrcode qrcode = new Qrcode();
		qrcode.setQrcodeErrorCorrect('M');// 纠错等级（分为L、M、H三个等级）
		qrcode.setQrcodeEncodeMode('B');// N代表数字，A代表a-Z，B代表其它字符
		qrcode.setQrcodeVersion(9);// 版本
		// 生成二维码中要存储的信息
		String qrData = "马蹄南去人北望";
		// 设置一下二维码的像素
		int width = 67 + 12 * (9 - 1);
		int height = 67 + 12 * (9 - 1);
		BufferedImage bufferedImage = new BufferedImage(width, height,
				BufferedImage.TYPE_INT_RGB);
		// 绘图
		Graphics2D gs = bufferedImage.createGraphics();
		gs.setBackground(Color.WHITE);
		gs.setColor(Color.BLACK);
		gs.clearRect(0, 0, width, height);// 清除下画板内容

		// 设置下偏移量,如果不加偏移量，有时会导致出错。
		int pixoff = 2;

		byte[] d = null;
		try {
			d = qrData.getBytes("gb2312");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (d.length > 0 && d.length < 120) {
			boolean[][] s = qrcode.calQrcode(d);
			for (int i = 0; i < s.length; i++) {
				for (int j = 0; j < s.length; j++) {
					if (s[j][i]) {
						gs.fillRect(j * 3 + pixoff, i * 3 + pixoff, 3, 3);
					}
				}
			}
		}
		gs.dispose();
		bufferedImage.flush();
		try {
			ImageIO.write(bufferedImage, "png", new File("D:\\picture"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void void2(String[] args) throws Exception {
		Qrcode qrcode = new Qrcode();
		qrcode.setQrcodeErrorCorrect('M');// 纠错等级（分为L、M、H三个等级）
		qrcode.setQrcodeEncodeMode('B');// N代表数字，A代表a-Z，B代表其它字符
		qrcode.setQrcodeVersion(9);// 版本
		// 生成二维码中要存储的信息
		String qrData = "";

		// 设置一下二维码的像素
		int width = 67 + 12 * (9 - 1);
		;
		int height = 67 + 12 * (9 - 1);
		;
		BufferedImage bufferedImage = new BufferedImage(width, height,
				BufferedImage.TYPE_INT_RGB);
		// 绘图
		Graphics2D gs = bufferedImage.createGraphics();
		gs.setBackground(Color.WHITE);
		gs.setColor(Color.BLACK);
		gs.clearRect(0, 0, width, height);// 清除下画板内容

		// 设置下偏移量,如果不加偏移量，有时会导致出错。
		int pixoff = 2;

		byte[] d = qrData.getBytes("gb2312");
		if (d.length > 0 && d.length < 120) {
			boolean[][] s = qrcode.calQrcode(d);
			for (int i = 0; i < s.length; i++) {
				for (int j = 0; j < s.length; j++) {
					if (s[j][i]) {
						gs.fillRect(j * 3 + pixoff, i * 3 + pixoff, 3, 3);
					}
				}
			}
		}
		gs.dispose();
		bufferedImage.flush();
		ImageIO.write(bufferedImage, "png", new File("E:/code/qrcode0.png"));
	}

	@Test
	public void show2() {

		String s = "		createQCImage(Member [pageIndex=1, pageSize=5, mid=1000, mname=admin, msex=1, mphone=13809989890, mcard=37066789890990, mqq=123, mweixin=qweqwe, maddress=北京市中关村01号, mcreatetime=Mon Mar 19 16:18:33 CST 2018, departmentid=0])";

		// Arrays.asList(s.split(" "));
		// s.trim();
		System.out.println(s.trim().replaceAll(" ", ""));
		;

	}
	
	public static void main(String[] args) {
		String path0 = "D:/code";
        String path1 = "D:/code/kkk.txt";
        File f = new File(path0);
        // 创建文件夹
        if (!f.exists()) {
            f.mkdirs();
        }
        f = new File(path1);
        // 创建文件
        if (!f.exists()) {
            try {
                f.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
	}

}
